<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <p class="class">i am a text</p>
    <p class="class">i am a text</p>
    <p class="class">i am a text</p>
    <p class="class">i am a text</p>
    <p class="class">i am a text</p>
    <p class="class">i am a text</p>
    <script>
        let txts = document.querySelectorAll('.class')
        let txts1 = document.getElementsByClassName('class')//通过类名找txts1，然后再修改类名。txts1会动态变化的
        console.log(txts)
        // txts.forEach(element=>element.className='new_class')
        for (var i = 0; i < txts1.length; i++) {
            txts1[i].className = 'new_class'
        }

    </script>
</body>

</html>